import request from "@/util/request";

export const getUser = () => {
  return request({
    url: "/users/getAll",
    method: "getInfo",
  });
};

export const getUserById = (id: number) => {
  return request({
    url: `users/getById/${id}`,
    method: "get",
  });
};

export const updateUserInfo = (data: any) => {
  return request({
    url: "/users/update",
    method: "post",
    data: data,
  });
};

export const loginApi = (data: any) => {
  return request({
    url: "/users/login",
    method: "post",
    data: data,
  });
};

export const registerApi = (data: any) => {
  return request({
    url: "/users/register",
    method: "post",
    data: data,
  });
};

// 向后端传入用户名或手机号作为查询条件
export const getUserInfoApi = (query: any) => {
  return request({
    url: "/users/getAll",
    method: "get",
    params: query,
  });
};

// 上传头像
export const uploadAvatar = (formData: FormData) => {
  return request({
    url: "/users/uploadAvatar",
    method: "post",
    headers: {
      "Content-Type": "multipart/form-data",
    },
    data: formData,
  });
};

// 修改密码
export const updatePassword = (data: {
  userId: number;
  oldPassword: string;
  newPassword: string;
}) => {
  return request({
    url: "/users/resetPassword",
    method: "post",
    data,
  });
};
